/*
 * utils.h
 *
 *  Created on: 2022年2月4日
 *      Author: TamGitsun
 */

#ifndef UTILS_H_
#define UTILS_H_

#include <tos_k.h>
#include <stdio.h>

typedef struct
{
	unsigned short year;
	unsigned short month;
	unsigned short date;
	unsigned short day;
	unsigned short hour;
	unsigned short minute;
	unsigned short second;
} T_TIME;

typedef enum
{
	DIFF_LEVEL_YEAR = 1,
	DIFF_LEVEL_MONTH = 2,
	DIFF_LEVEL_DAY = 4,
	DIFF_LEVEL_HOUR = 8,
	DIFF_LEVEL_MINUTE = 16,
	DIFF_LEVEL_SECOND = 32
} E_DIFF_LEVEL;

typedef unsigned long day_t;

k_tick_t get_sys_time(void);

void set_sys_time(k_tick_t t);

T_TIME get_time(k_tick_t * t);

void get_format_time(char * buffer, size_t size);

void get_format_time_of_day(char * buffer, size_t size);

void get_format_date(char * buffer, size_t size);

void k_tick_t_2_format_time(k_tick_t t, char * buffer, size_t size);

void k_tick_t_2_format_time_of_day(k_tick_t t, char * buffer, size_t size);

void k_tick_t_2_format_date(k_tick_t t, char * buffer, size_t size);

int date_cmp(T_TIME t1, T_TIME t2);

int date_diff(T_TIME t1, T_TIME t2, int diff_level);

day_t k_tick_t_2_day_t(k_tick_t t);

k_tick_t day_t_2_k_tick_t(day_t day);

int k_tick_t_2_day_seconds(k_tick_t t);

k_tick_t str_2_k_tick_t(const char * str);

void k_tick_t_2_str(k_tick_t t, char * buf, size_t size);


typedef struct random_int_generator_t
{
	uint32_t seed;
	int range_begin;
	int range_end;
	int (*next)(struct random_int_generator_t * generator);
} random_int_generator_t;

void random_int_generator(random_int_generator_t * generator, int range_begin, int range_end);


#endif /* UTILS_H_ */
